Optimal Control For Closed And Open Systems